<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>Document</title>
<link rel="stylesheet" href="../assets/agile/css/ratchet/css/ratchet.min.css">
<link rel="stylesheet" href="../assets/agile/css/flat/flat.component.css">
<link rel="stylesheet" href="../assets/agile/css/flat/iconline.css">
<link rel="stylesheet" href="../assets/app/css/app.css" />
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/local.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
</head>
<body>
<!--通用顶部-->
<div id="ios-top-box">
    <div id="header" class="bar bar-nav">
    <div class="titlebar">
    <a href="javascript:appClose('wxcode',api);"><i class="iconfont iconline-arrow-left"></i></a>
    <h1 class="title">保存二维码</h1>
    </div>
    </div>
</div>
<!--通用顶部结束-->
<section>
<div class="wrap-padding create_ok">
<img data-original="" class="lazy" width="60%" style="display: block;margin:10px auto;" />
<p>分享二维码赚佣金</p>
<p><button class="common-btn" id="save">保存到手机</button></p>
<p><button class="common-btn" id="shareWx">分享到微信</button></p>
</div>
</section>
</body>
<script>
$(function(){
	if(getUserinfo()){
		var userinfo = getUserinfo();
		GetJPData(config.url+'/app.php?act=wxcode&uid='+userinfo.uid,{},function(data){
			if(data['status']){
				$('img').attr('data-original',data['file']);
				$('#save').click(function(){
					var file = data['file'];
					api.download({
					    url: file,
					    report: true,
					    cache: true,
					    allowResume: true
					},function( ret, err ){
					    if(ret['state'] == 1){
							api.saveMediaToAlbum({
							    path: ret['savePath']
							}, function( ret, err ){ 
							    if(ret['status']){
							        $.PageDialog.ok('<s></s>保存成功');
							    }else{
							        $.PageDialog.fail('保存失败');
							    }
							});
					    }else{
					    	$.PageDialog.fail('保存失败');
					    }
					});
				});


   $('#shareWx').click(function(){
        var wx = api.require('wx');
            wx.isInstalled(function(ret, err){
            	//alert(config.wxpay.app_id);
                if(ret.installed){
					api.download({
					    url: data['file'],
					    report: true,
					    cache: true,
					    allowResume: true
					},function(ret,err){
                    wx.shareImage({
                        apiKey: config.wxpay.app_id,
                        scene: 'session',
                        thumb: 'widget://res/_r1_c1.png',
                        contentUrl: ret['savePath'],
                    }, function(ret, err){
                        if(ret.status){
                            appToast('分享成功');
                        }else{
                            //
							//alert(JSON.stringify(err));
                        }
                    });
					});

                }else{
                    api.alert({msg:'当前设备未安装微信客户端'});
                }
            });
   });



			}
			lyzimg();

		});
	}else{
		$.PageDialog.fail('请登录用户');
	}
	lyzimg();
});
</script>
</html>